<?php require_once(dirname(__FILE__).'/inc/config.inc.php');
if ( $_SESSION['adminlevel']>1  &&  $_SESSION['is_wage']!='1' ){
	echo "你没有权限";
	exit();
}
require_once "function.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>修改工资信息</title>
	<link href="templates/style/admin.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="templates/js/jquery.min.js"></script>
	<script type="text/javascript" src="layer/layer.js"></script>
	<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
	<link rel="stylesheet" href="ui/css/bootstrap.min.css">
	<link rel="stylesheet" href="ui/css/bootstrap-theme.min.css" >
	<link rel="stylesheet" href="templates/js/zoomify.min.css">
	<script language="javascript" type="text/javascript" src="DatePicker/WdatePicker.js"></script>
	<style type="text/css">
		.main_box{width: 950px;margin:0 auto; height: auto; overflow: hidden;}
		.main_box h1{ text-align: center; }
		.mb10{ margin-bottom: 10px; }
		.w58{ width: 50px !important }
		.tx-l{ text-align: left; }
		.w650{ width: 650px; }
		.f-b{ font-weight: bold; color: red; }
		.table{ margin:0 !important; }
	</style>
</head>
<body>
	<?php
	$sql="SELECT f.* ,u.truename as truename,u.zhiwu as zhiwuid,u.id as newuid,u.join_time  FROM `#@__wage` as f
	left join `#@__user`   as u on u.id=f.uid
	left join `#@__cascadedata` as z on z.datavalue=u.zhiwu WHERE f.`id`=$id";
	$row = $dosql->GetOne($sql);

	$uid=$row['uid'];

	$zhiwuname=cascadedata('zhiwu',$row['zhiwuid']);
	$uname=$row['truename'];
	$join_time=date("Y-m-d",$row['join_time']);
	//$join_year=floor((time()-$row['join_time'])/(365*24*60*60));
    $creat_time=$row['creat_time'];
    $join_year=floor(($creat_time-$row['join_time']-30*24*3600)/(365*24*60*60));
    //$join_year=floor((time()-$row['join_time'])/(365*24*60*60));
    $gongligongzi=$row['gongling_wage'];
	//基础补助
	$jichugongzi=$row['zhiwu_wage']+$row['dixin_wage']+$row['dianhua_wage']+$row['jiadang_wage']+$row['weisheng_wage']+$gongligongzi+$row['tuandui_wage']+$row['quanqin_wage'];
	//其他补助
	$qitabuzhu=$row['yewu_wage']+$row['ticheng_wage']+$row['zhusu_wage']+$row['bukuan_wage'];
	//总计工资
	$zongji_wage=$jichugongzi+$qitabuzhu+$row['yiliao_wage']+$row['yanglao_wage']+$row['gongshang_wage'];

	//实发工资
	$shiji_wage=$zongji_wage-$row['f_kaoqin_wage']-$row['f_yanglao_wage']-$row['f_yiliao_wage']-$row['f_gongjijin_wage']-$row['f_qita_wage'];
	?>
	
	<div class="main_box" >
		<h1>修改 <?php echo $uname;?>-<?php echo date("Y-m",$row['wage_month'])?> 月份工资</h1>
		<table  class="table mb10" >
			<tr><td width="80%"><span class="red">[工资月份：<?php echo date("Y-m",$row['wage_month'])?>] </span> 工资表制作日期: 
				<?php echo date("Y-m-d H:i:s",$row['creat_time'])?>
				<input type="hidden" name="wage_month" id="wage_month" value="<?php echo date("Y-m",$row['wage_month'])?>">
			</td>
				<td width="20%"> </td>
			</tr>
		</table>


		<div class="panel panel-primary">
			<div class="panel-heading">
				<h3 class="panel-title">基础工资</h3>
			</div>
			<div class="panel-body">
				<table class="table table-bordered">
					<tr>
						<td width="10%">姓名:</td><td class="red" width="15%"><?php echo $uname;?></td>
						<td width="10%">职务：</td><td class="red" width="15%"><?php echo $zhiwuname;?></td>
						<td width="15%">入职时间:</td><td class="red" width="10%"><?php echo $join_time;?></td>
						<td width="12.5%">工龄：</td><td class="red" width="12.5%"><?php echo $join_year;?> 年</td>
					</tr>
					<tr>
						<td width="10%">职务工资:</td><td class="red" width="15%"><input onkeyup="SumNum()" type="text" class="w58" name="zhiwu_wage" id="zhiwu_wage" value="<?php echo $row['zhiwu_wage'];?>"></td>
						<td width="10%">底薪：</td><td class="red" width="15%"><input  onkeyup="SumNum()" type="text" class="w58" name="dixin_wage" id="dixin_wage" value="<?php echo $row['dixin_wage'];?>"></td>
						<td width="15%">电话费:</td><td class="red" width="10%"><input onkeyup="SumNum()" type="text" class="w58" name="dianhua_wage" id="dianhua_wage" value="<?php echo $row['dianhua_wage'];?>"></td>
						<td width="12.5%">工资加档：</td><td class="red" width="12.5%"><input onkeyup="SumNum()" type="text" class="w58" name="jiadang_wage" id="jiadang_wage" value="<?php echo $row['jiadang_wage'];?>"></td>
					</tr>
					<tr>
						<td width="10%">卫生奖:</td><td class="red" width="15%"><input onkeyup="SumNum()" type="text" class="w58" name="weisheng_wage" id="weisheng_wage" value="<?php echo $row['weisheng_wage'];?>"></td>
						<td width="10%">工龄工资：</td><td class="red" width="15%"><input onkeyup="SumNum()" readonly="" type="text" class="w58" name="gongling_wage" id="gongling_wage" value="<?php echo $gongligongzi;?>">实发<?php echo $row['gongling_wage'];?></td>
						<td width="15%">团队协作奖:</td><td class="red" width="10%"><input onkeyup="SumNum()"  type="text" class="w58" name="tuandui_wage" id="tuandui_wage" value="<?php echo $row['tuandui_wage'];?>"></td>
						<td width="12.5%">全勤奖：</td><td class="red" width="12.5%"><input onkeyup="SumNum()" type="text" class="w58" name="quanqin_wage" id="quanqin_wage" value="<?php echo $row['quanqin_wage'];?>"></td>
					</tr>
					<tr>
						<td width="10%"  class="f-b">基础工资:</td><td class="red" colspan="7" width="90%"><input type="text" class="w58" name="jichugongzi" id="jichugongzi" value="<?php echo $jichugongzi;?>"></td>

					</tr>
				</table>
			</div>
		</div>
		<div class="panel panel-danger">
			<div class="panel-heading">
				<h3 class="panel-title">其他补款</h3>
			</div>
			<div class="panel-body">
				<table class="table table-bordered">
					<tr>
						<td width="10%">派单补贴:</td><td class="red" width="15%"><input onkeyup="SumNum()"  type="text" class="w58" name="yewu_wage" id="yewu_wage" value="<?php echo $row['yewu_wage'];?>"></td>
						<td width="10%">业务提成：</td><td class="red" width="15%"><input onkeyup="SumNum()" type="text" class="w58" name="ticheng_wage" id="ticheng_wage" value="<?php echo $row['ticheng_wage'];?>"></td>
						<td width="10%">住宿补贴:</td><td class="red" width="15%"><input onkeyup="SumNum()" type="text" class="w58" name="zhusu_wage" id="zhusu_wage" value="<?php echo $row['zhusu_wage'];?>"></td>
						<td width="12.5%">其他补助：</td><td class="red" width="12.5%"><input onkeyup="SumNum()" type="text" class="w58" name="bukuan_wage" id="bukuan_wage" value="<?php echo $row['bukuan_wage'];?>"></td>
					</tr>
					<tr>
						<td colspan="8" >其他补助说明:
							<input type="text" class="w650" name="bukuan_summary" id="bukuan_summary" value="<?php echo trim($row['bukuan_summary']);?>">
						</td>

					</tr>
					<tr>
						<td width="10%" class="f-b">其他补款:</td><td class="red" colspan="7" width="90%"><input type="text" class="w58" name="qitabuzhu" id="qitabuzhu" value="<?php echo $qitabuzhu;?>"></td>

					</tr>
				</table>
			</div>
		</div>
		<div class="panel panel-success">
			<div class="panel-heading">
				<h3 class="panel-title">保险缴纳</h3>
			</div>
			<div class="panel-body">
				<table class="table table-bordered">
					<tr>
						<td width="18%">养老保险:</td><td class="red" width="18%"><input onkeyup="SumNum()" type="text" class="w58" name="yanglao_wage" id="yanglao_wage" value="<?php echo $row['yanglao_wage'];?>"></td>
						<td width="18%">医疗保险：</td><td class="red" width="18%"><input onkeyup="SumNum()" type="text" class="w58" name="yiliao_wage" id="yiliao_wage" value="<?php echo $row['yiliao_wage'];?>"></td>
						<td width="18%">工伤保险:</td><td class="red" colspan="3" ><input onkeyup="SumNum()" type="text" class="w58" name="gongshang_wage" id="gongshang_wage" value="<?php echo $row['gongshang_wage'];?>"></td>

					</tr>
					<tr>
						<td width="18%" class="f-b">当月应发工资:</td><td class="red" colspan="7" width="89%"><input type="text" class="w58" name="zongji_wage" id="zongji_wage" value="<?php echo $zongji_wage;?>"></td>

					</tr>
				</table>
			</div>
		</div>

		<div class="panel panel-info">
			<div class="panel-heading">
				<h3 class="panel-title">实发工资</h3>
			</div>
			<div class="panel-body">
				<table class="table table-bordered">
					<tr>
						<td width="15%">考勤扣款:</td><td class="red" width="10%"><input onkeyup="SumNum()" type="text" class="w58" name="f_kaoqin_wage" id="f_kaoqin_wage" value="<?php echo $row['f_kaoqin_wage'];?>"></td>
						<td width="15%">养老保险扣款：</td><td class="red" width="10%"><input onkeyup="SumNum()" type="text" class="w58" name="f_yanglao_wage" id="f_yanglao_wage" value="<?php echo $row['f_yanglao_wage'];?>"></td>
						<td width="15%">医疗保险扣款：</td><td class="red" width="10%" ><input onkeyup="SumNum()"  type="text" class="w58" name="f_yiliao_wage" id="f_yiliao_wage" value="<?php echo $row['f_yiliao_wage'];?>"></td>
						<td width="15%">公积金扣款：</td><td class="red" width="10%" ><input onkeyup="SumNum()" type="text" class="w58" name="f_gongjijin_wage" id="f_gongjijin_wage" value="<?php echo $row['f_gongjijin_wage'];?>"></td>
					</tr>
					<tr>
						<td width="15%">其他扣款:</td><td class="red" width="10%"><input onkeyup="SumNum()" type="text" class="w58" name="f_qita_wage" id="f_qita_wage" value="<?php echo $row['f_qita_wage'];?>"></td>
						<td width="15%">其他扣款说明</td><td class="red" colspan="5" width="60%"><input type="text" class="w500" name="f_qita_summary" id="f_qita_summary" value="<?php echo $row['f_qita_summary'];?>"></td>

					</tr>
					<tr>
						<td width="15%" class="f-b">当月实发工资:</td><td class="red" colspan="7" width="75%"><input type="text" class="w58" name="shiji_wage" id="shiji_wage" value="<?php echo $shiji_wage;?>"></td>

					</tr>
				</table>
			</div>
		</div>
	</div>
	<input type="hidden" name="id" id="id" value="<?php echo $id;?>">
	<input type="hidden" name="action" value="update">
	<table class="table cc">
		<tr><td><a class="btn btn-danger" href="javascript:;" onclick="submit_wage()">确认修改工资单</a> </td></tr>
	</table>
	<!--js 监听加载-->
	<script type="text/javascript">
		function SumNum(){
		//基础
		var zhiwu_wage=$("#zhiwu_wage").val();
		var dixin_wage=$("#dixin_wage").val();
		var dianhua_wage=$("#dianhua_wage").val();
		var jiadang_wage=$("#jiadang_wage").val();
		var weisheng_wage=$("#weisheng_wage").val();
		var gongling_wage=$("#gongling_wage").val(); //工龄工资
		var tuandui_wage=$("#tuandui_wage").val();
		var quanqin_wage=$("#quanqin_wage").val();
		var jichugongzi=parseFloat(zhiwu_wage)+parseFloat(dixin_wage)+parseFloat(dianhua_wage)+parseFloat(weisheng_wage)+parseFloat(jiadang_wage)+parseFloat(gongling_wage)+parseFloat(tuandui_wage)+parseFloat(quanqin_wage);
		$("#jichugongzi").val(jichugongzi);
		//补助
		var yewu_wage=$("#yewu_wage").val();
		var ticheng_wage=$("#ticheng_wage").val();
		console.log("提成"+ticheng_wage);
		var zhusu_wage=$("#zhusu_wage").val();
		var bukuan_wage=$("#bukuan_wage").val(); 
		console.log("业务"+yewu_wage);
		var qitabuzhu=parseFloat(yewu_wage)+parseFloat(ticheng_wage)+parseFloat(zhusu_wage)+parseFloat(bukuan_wage);
		$("#qitabuzhu").val(qitabuzhu);


		//保险缴纳
		var yanglao_wage=$("#yanglao_wage").val();
		var yiliao_wage=$("#yiliao_wage").val();
		var gongshang_wage=$("#gongshang_wage").val();
		var bukuan_wage=$("#bukuan_wage").val(); 
		var zongji_wage=jichugongzi+qitabuzhu+parseFloat(yanglao_wage)+parseFloat(yiliao_wage)+parseFloat(gongshang_wage);
		$("#zongji_wage").val(zongji_wage);

		//扣款
		var f_kaoqin_wage=$("#f_kaoqin_wage").val();
		var f_yanglao_wage=$("#f_yanglao_wage").val();
		var f_yiliao_wage=$("#f_yiliao_wage").val();
		var f_gongjijin_wage=$("#f_gongjijin_wage").val(); 
		var f_qita_wage=$("#f_qita_wage").val(); 
		var shiji_wage=zongji_wage-parseFloat(f_kaoqin_wage)-parseFloat(f_yanglao_wage)-parseFloat(f_yiliao_wage)-parseFloat(f_gongjijin_wage)-parseFloat(f_qita_wage);
		$("#shiji_wage").val(shiji_wage);
	}

	function submit_wage(){
		var id=$("#id").val();
		var zhiwu_wage=$("#zhiwu_wage").val();
		var dixin_wage=$("#dixin_wage").val();
		var dianhua_wage=$("#dianhua_wage").val();
		var jiadang_wage=$("#jiadang_wage").val();
		var weisheng_wage=$("#weisheng_wage").val();
		var gongling_wage=$("#gongling_wage").val(); //工龄工资
		var tuandui_wage=$("#tuandui_wage").val();
		var quanqin_wage=$("#quanqin_wage").val();
		var yewu_wage=$("#yewu_wage").val();
		var ticheng_wage=$("#ticheng_wage").val();
		var zhusu_wage=$("#zhusu_wage").val();
		var bukuan_wage=$("#bukuan_wage").val(); 
		var yanglao_wage=$("#yanglao_wage").val();
		var yiliao_wage=$("#yiliao_wage").val();
		var gongshang_wage=$("#gongshang_wage").val();
		var bukuan_wage=$("#bukuan_wage").val(); 
		var f_kaoqin_wage=$("#f_kaoqin_wage").val();
		var f_yanglao_wage=$("#f_yanglao_wage").val();
		var f_yiliao_wage=$("#f_yiliao_wage").val();
		var f_gongjijin_wage=$("#f_gongjijin_wage").val(); 
		var f_qita_wage=$("#f_qita_wage").val(); 
		var bukuan_summary=$("#bukuan_summary").val(); 
		var f_qita_summary=$("#f_qita_summary").val(); 
		var wage_month=$("#wage_month").val(); 

		//提交操作
		 //操作 
		 $.ajax({
		 	type: 'POST',
		 	url: "wage_save.php",
		 	data: {
		 		id:id,
		 		action:'update',
		 		zhiwu_wage:zhiwu_wage,
		 		dixin_wage:dixin_wage,
		 		dianhua_wage:dianhua_wage,
		 		jiadang_wage:jiadang_wage,
		 		weisheng_wage:weisheng_wage,
		 		gongling_wage:gongling_wage,
		 		tuandui_wage:tuandui_wage,
		 		quanqin_wage:quanqin_wage,
		 		zhusu_wage:zhusu_wage,
		 		yewu_wage:yewu_wage,
		 		ticheng_wage:ticheng_wage,
		 		yanglao_wage:yanglao_wage,
		 		yiliao_wage:yiliao_wage,
		 		gongshang_wage:gongshang_wage,
		 		bukuan_wage:bukuan_wage,
		 		bukuan_summary:bukuan_summary,
		 		f_kaoqin_wage:f_kaoqin_wage,
		 		f_yanglao_wage:f_yanglao_wage,
		 		f_yiliao_wage:f_yiliao_wage,
		 		f_gongjijin_wage:f_gongjijin_wage,
		 		f_qita_wage:f_qita_wage,
		 		f_qita_summary:f_qita_summary,
		 		wage_month:wage_month
		 	},
		 	dataType: 'JSON',
		 	success:function(result){
		 		console.log(result);
		 		if(result.errno==0){
		 			console.log(result.errmsg);
		 			if(result.errmsg=="ok"){
		 				layer.alert('修改成功', {
						  skin: 'layui-layer-molv' //样式类名
						  ,closeBtn: 0
						}, function(){
							parent.location.reload(); // 父页面刷新
							var index = parent.layer.getFrameIndex(window.name); 
		 				 //先得到当前iframe层的索引
		 				 parent.layer.close(index); 
						//再执行关闭  
					});
		 				
		 			}else{
		 				layer.msg(result.errmsg);
		 			}
		 		}
		 	}
		 });


		}

	</script>
</body>
</html>